﻿<UserControl x:Class="WpfSimplexSolver.SimplexSolverControl"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:WpfSimplexSolver="clr-namespace:WpfSimplexSolver"
        MouseLeftButtonDown="UserControl_MouseLeftButtonDown" Loaded="UserControl_Loaded">
    <UserControl.Resources>
        <WpfSimplexSolver:SimplexSolverViewModel x:Key="viewModel" />
    </UserControl.Resources>
    <Grid x:Name="grid" DataContext="{StaticResource viewModel}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>
        <ScrollViewer VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto">
            <Grid>
                <Grid.RowDefinitions>
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="Auto" />
                    <RowDefinition Height="*" />
                    <RowDefinition Height="Auto" />
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <ItemsControl Grid.Row="0" Grid.Column="0" ItemsSource="{Binding UnknownCollection}"
                        HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" VerticalAlignment="Top"
                        HorizontalAlignment="Left">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal" />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Name}" Margin="3" Width="50" TextAlignment="Center" />
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
                <TextBlock Text="=&gt;" Grid.Row="1" Grid.Column="1" Margin="3" Width="50" Height="24"
                        TextAlignment="Center" VerticalAlignment="Center" />
                <ItemsControl Grid.Row="1" Grid.Column="0" ItemsSource="{Binding UnknownCollection}"
                        HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" VerticalAlignment="Top"
                        HorizontalAlignment="Left">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal" />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding Weight}" Margin="3" Width="50" Height="24" TextAlignment="Center" />
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
                <ComboBox Grid.Row="1" Grid.Column="2" ItemsSource="{Binding TaskCollection}" Margin="3" Width="50"
                        Height="24" SelectedItem="{Binding SelectedTask, Mode=TwoWay}" DisplayMemberPath="Name" />
                <ItemsControl Grid.Row="2" Grid.Column="0" ItemsSource="{Binding RestrictionCollection}"
                        HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" VerticalAlignment="Top">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Vertical" />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <ItemsControl ItemsSource="{Binding WeightCollection}" HorizontalContentAlignment="Stretch"
                                    HorizontalAlignment="Stretch">
                                <ItemsControl.ItemsPanel>
                                    <ItemsPanelTemplate>
                                        <StackPanel Orientation="Horizontal" />
                                    </ItemsPanelTemplate>
                                </ItemsControl.ItemsPanel>
                                <ItemsControl.ItemTemplate>
                                    <DataTemplate>
                                        <TextBox Text="{Binding Value, Mode=TwoWay}" Width="50" Height="24" Margin="3"
                                                TextAlignment="Center" />
                                    </DataTemplate>
                                </ItemsControl.ItemTemplate>
                            </ItemsControl>
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
                <ItemsControl Grid.Row="2" Grid.Column="1" ItemsSource="{Binding RestrictionCollection}"
                        HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" VerticalAlignment="Top"
                        HorizontalAlignment="Left">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Vertical" />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <ComboBox DisplayMemberPath="Name" Margin="3" Width="50" Height="24"
                                    ItemsSource="{Binding RestrictionSignCollection}"
                                    SelectedItem="{Binding SelectedRestrictionSign, Mode=TwoWay}" />
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
                <ItemsControl Grid.Row="2" Grid.Column="2" ItemsSource="{Binding RestrictionCollection}"
                        HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" VerticalAlignment="Top"
                        HorizontalAlignment="Left">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Vertical" />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding ResctrictionValue}" Margin="3" Width="50" Height="24"
                                    TextAlignment="Center" />
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>

                <ItemsControl Grid.Row="3" Grid.Column="0" ItemsSource="{Binding UnknownCollection}"
                        HorizontalContentAlignment="Stretch" VerticalContentAlignment="Stretch" VerticalAlignment="Top">
                    <ItemsControl.ItemsPanel>
                        <ItemsPanelTemplate>
                            <StackPanel Orientation="Horizontal" />
                        </ItemsPanelTemplate>
                    </ItemsControl.ItemsPanel>
                    <ItemsControl.ItemTemplate>
                        <DataTemplate>
                            <TextBox Text="{Binding Value, Mode=TwoWay}" Width="50" Height="24" Margin="3"
                                    IsReadOnly="True" TextAlignment="Center" />
                        </DataTemplate>
                    </ItemsControl.ItemTemplate>
                </ItemsControl>
                <TextBlock Text="=" TextAlignment="Center" Grid.Row="3" Grid.Column="1" VerticalAlignment="Center" />
                <TextBox Text="{Binding Result}" TextAlignment="Center" Grid.Row="3" Grid.Column="2"
                        VerticalAlignment="Center" Width="50" Height="24" Margin="3" IsReadOnly="True" />
            </Grid>
        </ScrollViewer>
        <StackPanel Grid.Row="1" Orientation="Horizontal">
            <Button Content="Add unknown" Click="onBtnAddUnknownClick" Margin="3" />
            <Button Content="Add restriction" Click="onBtnAddRestrictionClick" Margin="3" />
            <Button Content="Solve" Click="onBtnSolveClick" Margin="3" />
        </StackPanel>
    </Grid>
</UserControl>
